/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Interface.java
 *
 * Created on 10/05/2011, 19:29:41
 */

package metodogauss;

import GUI.CapturaImagens;
import GUI.ImagePanel;
import GUI.SwingCapture;
import deteccao.ControleMouse;
import ia.perceptron.RedeNeural;
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Igor
 */


public class Interface extends javax.swing.JFrame {

    private ImagePanel display;
    Point ponto = new Point(0,0);
    SwingCapture swing = new SwingCapture();

    ControleMouse cEntrada;
    CapturaImagens cap;

    /** Creates new form Interface */
    public Interface() {
        super("Programa do TCC");
        initComponents();
        display = new ImagePanel();
        this.setLocation(new Point(Toolkit.getDefaultToolkit().getScreenSize().width-400,Toolkit.getDefaultToolkit().getScreenSize().height-400));
        this.setSize(new Dimension(366,355));
        PainelPrincipal.setLayout(new BorderLayout());
        PainelPrincipal.add(display);
        PainelPrincipal.repaint();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PainelPrincipal = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        CarregarImg = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        setFocusTraversalPolicyProvider(true);

        PainelPrincipal.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true));
        PainelPrincipal.setPreferredSize(new java.awt.Dimension(640, 480));

        javax.swing.GroupLayout PainelPrincipalLayout = new javax.swing.GroupLayout(PainelPrincipal);
        PainelPrincipal.setLayout(PainelPrincipalLayout);
        PainelPrincipalLayout.setHorizontalGroup(
            PainelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 605, Short.MAX_VALUE)
        );
        PainelPrincipalLayout.setVerticalGroup(
            PainelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 558, Short.MAX_VALUE)
        );

        jMenu1.setText("Arquivo");

        CarregarImg.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, java.awt.event.InputEvent.CTRL_MASK));
        CarregarImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Hand.png"))); // NOI18N
        CarregarImg.setText("Carregar Imagem");
        CarregarImg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CarregarImgActionPerformed(evt);
            }
        });
        jMenu1.add(CarregarImg);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, 0));
        jMenuItem5.setText("Soltar Botão (Hold)");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(PainelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 609, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(PainelPrincipal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CarregarImgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CarregarImgActionPerformed
        RedeNeural rede = new RedeNeural();
        //Neuronio neuronio = new Neuronio();
        //neuronio.treinar();
       // PerceptronMultiLayer percep = new PerceptronMultiLayer();
        cap = new CapturaImagens();
        cap.setNeuralNetwork(rede.getNeuralNetwork());
        //cap.setRede(percep);
        //cap.setNeuronio(neuronio);
        try {
            cEntrada = new ControleMouse();
        } catch (AWTException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }
        cap.setMouse(cEntrada);
        cap.setCap(swing);
        cap.setPainel(this.display);
        try {
            cap.sleep(500);
            
        } catch (InterruptedException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }
        cap.start();
        
    }//GEN-LAST:event_CarregarImgActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        cEntrada.mouseRelease(InputEvent.BUTTON1_MASK);
        this.toFront();
        this.requestFocus();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Interface().setVisible(true);
            }
        });
    }

    public ControleMouse getcEntrada() {
        return cEntrada;
    }

    public void setcEntrada(ControleMouse cEntrada) {
        this.cEntrada = cEntrada;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem CarregarImg;
    private javax.swing.JPanel PainelPrincipal;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem5;
    // End of variables declaration//GEN-END:variables
     

}
